package com.cyanite.playlv2.widget;

import com.cyanite.playlv2.R;
import com.cyanite.playlv2api.types.Group;
import com.cyanite.playlv2api.types.Secret;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class SecretListAdapter extends BaseAdapter{

    private Group<Secret> mSecrets;
    private LayoutInflater mInflater;

    public SecretListAdapter(Context context,Group<Secret> secrets) {
        mSecrets = secrets;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;

       if (convertView == null) {
            convertView = mInflater.inflate(R.layout.secret_list_item, null);
            holder = new ViewHolder();
            holder.description = (TextView) convertView.findViewById(R.id.tvSecretDescription);
            holder.date = (TextView) convertView.findViewById(R.id.tvSecretDate);
            holder.address = (TextView) convertView.findViewById(R.id.tvSecretAddress);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
       
        Secret secret = mSecrets.get(position);
        holder.description.setText(secret.getTitle());
        holder.date.setText(secret.getPostDate());
        holder.address.setText(secret.getAddress());

        return convertView;
    }

    @Override
    public int getCount() {
        return mSecrets.size();
    }

    @Override
    public Object getItem(int position) {
        return mSecrets.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
    
    static class ViewHolder {
        TextView description;
        TextView date;
        TextView address;
    }
}
